package com.oa.hyperion.api.v1;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.oa.hyperion.entity.Menu;
import com.oa.hyperion.service.MenuService;
import com.oa.hyperion.service.RoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Liu
 * @date 2022年01月18日 16:16
 */
@RestController
@RequestMapping("v1/menus")
@Api(tags = "rbac相关接口")
public class MenuController {
    private final MenuService menuService;
    private final RoleMenuService roleMenuService;
    public MenuController(MenuService menuService, RoleMenuService roleMenuService) {
        this.menuService = menuService;
        this.roleMenuService = roleMenuService;
    }

    @GetMapping
    @ApiOperation("获取所有的菜单")
    public List<Menu> getAllMenu() {
        return menuService.list();
    }

    @GetMapping("by/role/{id}")
    @ApiOperation("查询角色拥有的菜单")
    public List<Menu> getMenuByRoleId(@ApiParam("角色ID") @PathVariable Integer id) {
        return roleMenuService.findMenuByRole(id);
    }

    @DeleteMapping("{id}")
    @ApiOperation("逻辑删除菜单")
    public String deleteMenu(@PathVariable Integer id) {
        menuService.update(new UpdateWrapper<Menu>().set("status", "n").eq("id", id));
        return "删除成功";
    }


}
